
<div class="mod-global global-setting">
  <tabset class="mod-tab">
    <tab heading="用户管理" active="vm.tabActive[0].active" ui-sref="globalSetting.userinfo">
      <div class="user-list-title">
        <input placeholder="输入用户名称查找" ng-model="vm.key.userKey" class="ui-input-fill ui-input-search pull-right"/>
        <h3>用户列表</h3>
        <div select-con="select-con" class="com-select-con">
          <button ng-cloak="ng-cloak" class="ui-btn ui-btn-select ui-btn-white"><i class="icon-down"></i>{{vm.currentUserType.type=='USER'?'普通用户':vm.currentUserType.type}}</button>
          <ul class="select-list">
            <li class="select-item"><a ng-click="vm.toggleUserType('LDAP');">LDAP</a></li>
            <li class="select-item"><a ng-click="vm.toggleUserType('USER');">普通用户</a></li>
          </ul>
        </div>
        <div ng-if="vm.currentUserType.type=='USER'" class="to-add">
          <button ng-if="!vm.isShowAdd" ng-click="vm.toggleShowAdd()" class="ui-btn ui-btn-primary ui-btn-sm">创建用户<i class="icon-down-white up"></i></button>
          <button ng-if="vm.isShowAdd" ng-click="vm.toggleShowAdd()" class="ui-btn ui-btn-primary ui-btn-sm">取消<i class="icon-down-white"></i></button>
        </div>
      </div>
      <ul ng-form="ng-form" name="userForm" role="form" ng-class="{'need-valid':vm.needValidUser.valid}" ng-show="vm.isShowAdd" class="com-list-info add-user">
        <li><span class="info-name">用户名</span>
          <div class="info-content">
            <input placeholder="由小写字母和数字组成" name="newuser" ng-model="vm.newUser.username" is-user-exist="vm.userList" required="required" ng-pattern="/^[0-9a-z]+$/" class="ui-input-white line-single"/><span ng-if="(vm.needValidUser.valid||userForm.newuser.$dirty)&amp;&amp;userForm.newuser.$error.pattern" class="txt-error">非法的名称</span><span ng-if="(vm.needValidUser.valid||userForm.newuser.$dirty)&amp;&amp;userForm.newuser.$error.isUserExist" class="txt-error">用户已存在</span>
          </div>
        </li>
        <li><span class="info-name">密码</span>
          <div class="info-content">
            <input placeholder="8-20位" type="password" ng-model="vm.newUser.password" name="newpw" ng-model-options="{updateOn:'default blur',debounce:{default:500,blur:0}}" required="required" ng-minlength="8" ng-maxlength="20" class="ui-input-white line-single"/><span ng-if="(vm.needValidUser.valid||userForm.newpw.$dirty)&amp;&amp;(userForm.newpw.$error.minlength||userForm.newpw.$error.maxlength)" class="txt-error">长度必须为8-20位</span>
          </div>
        </li>
        <li><span class="info-name">再次输入密码</span>
          <div class="info-content">
            <input placeholder="重新输入密码" type="password" ng-model="vm.newUser.rePassword" name="password" ng-model-options="{updateOn:'default blur',debounce:{default:500,blur:0}}" required="required" equal="newUser.password" class="ui-input-white line-single"/><span ng-if="(vm.needValidUser.valid||userForm.password.$dirty)&amp;&amp;userForm.password.$error.equal" class="txt-error">两次密码不一致</span>
          </div>
        </li>
        <li><span class="info-name">邮箱</span>
          <div class="info-content">
            <input ng-model="vm.newUser.email" name="email" required="required" class="ui-input-white line-single"/>
          </div>
        </li>
        <li><span class="info-name">电话</span>
          <div class="info-content">
            <input ng-model="vm.newUser.phone" name="phone" class="ui-input-white line-single"/>
            <div class="txt-wrap">
              <button ng-click="vm.needValidUser.valid=true;userForm.$valid&amp;&amp;vm.addUser(userForm);" class="ui-btn ui-btn-primary ui-btn-sm">确认创建</button>
            </div>
          </div>
        </li>
      </ul>
      <table class="ui-table-dome full table-userlist">
        <thead>
          <tr>
            <th>用户名</th>
            <th>邮箱</th>
            <th>电话</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-if="!vm.userList||userFiltered.length===0">
            <td colspan="3">无相关用户信息</td>
          </tr>
          <tr ng-repeat="user in userFiltered=(vm.userList|filter:{'username':vm.key.userKey,'loginType':vm.currentUserType.type})">
            <td ng-bind="user.username"></td>
            <td><span ng-bind="user.email||'未设置'" class="useremail tool-nowrap"></span></td>
            <td><span ng-bind="user.phone||'未设置'" class="useremail tool-nowrap"></span>
            </td>
            <td>
              <button ng-click="vm.modifyPw(user)" ng-if="vm.currentUserType.type=='USER'" class="ui-btn ui-btn-primary ui-btn-sm">修改密码</button><a ng-click="vm.modifyUserInfo(user)" class="icon-edit"></a><a ng-click="vm.deleteUser(user)" ng-if="user.username!='admin'" class="icon-delete"></a>
            </td>
          </tr>
        </tbody>
      </table>
    </tab>
    <tab heading="LDAP" ng-click="vm.getLdap()" active="vm.tabActive[1].active" ui-sref="globalSetting.ldapinfo">
      <ul ng-form="ng-form" name="ladpForm" ng-class="{'need-valid':vm.needValidLdap}" class="com-list-info ldap-info">
        <li><span class="info-name">OpenLDAP服务器地址</span>
          <div class="info-content">
            <input placeholder="IP或域名" name="ladpUrl" ng-model="vm.ldapInfo.url" required="required" ng-pattern="/^[^\s]*$/" class="ui-input-white line-single"/>
            <input placeholder="端口，如：389" name="ladpPort" ng-model="vm.ldapInfo.port" required="required" ng-pattern="/^[^\s]*$/" class="ui-input-white line-single"/>
          </div>
        </li>
        <li><span class="info-name">email后缀</span>
          <div class="info-content">
            <input ng-model="vm.ldapInfo.emailSuffix" name="ladpEmail" ng-pattern="/^[^\s]*$/" class="ui-input-white line-single"/>
          </div>
        </li>
      </ul>
      <div class="com-bottom-option">
        <button ng-click="vm.needValidLdap=true;ladpForm.$valid&amp;&amp;vm.saveLdap()" class="ui-btn ui-btn-bright ui-btn-md">保存配置</button>
      </div>
    </tab>
    <tab heading="代码仓库" ng-click="vm.getGitInfo()" active="vm.tabActive[2].active" ui-sref="globalSetting.gitinfo">
      <ul ng-form="ng-form" name="gitForm" ng-class="{'need-valid':vm.needValidGit}" class="com-list-info">
        <li><span class="info-name">选择类型</span>
          <div class="info-content com-chose-repository"><span class="repository active"><i class="icon-gitlab"></i>GitLab</span>
            <p class="txt-prompt">每种类型可分别配置一个代码仓库</p>
          </div>
        </li>
        <li><span class="info-name">代码仓库地址</span>
          <div class="info-content">
            <input ng-model="vm.gitInfo.url" name="gitUrl" required="required" ng-pattern="/^[^\s]*$/" class="ui-input-white line-single"/>
          </div>
        </li>
      </ul>
      <div class="com-bottom-option">
        <button ng-click="vm.needValidGit=true;gitForm.$valid&amp;&amp;vm.saveGit()" class="ui-btn ui-btn-bright ui-btn-md">保存配置</button>
      </div>
    </tab>
    <tab heading="私有仓库" ng-click="vm.getRegistryInfo()" active="vm.tabActive[3].active" ui-sref="globalSetting.registryinfo">
      <ul ng-form="ng-form" name="registryForm" ng-class="{'need-valid':vm.needValidRegistry}" class="com-list-info">
        <li><span class="info-name">私有仓库地址</span>
          <div class="info-content">
            <input ng-model="vm.registryInfo.url" name="registryUrl" required="required" ng-pattern="/^[^\s]*$/" style="display:inline-block" class="ui-input-white line-single"/><span>
              <input type="checkbox" name="isHttps" id="isHttps" ng-model="vm.registryInfo.status" ng-true-value="1" ng-false-value="0" class="ui-check"/>
              <label for="isHttps">https</label></span>
          </div>
        </li>
        <li><span class="info-name">描述</span>
          <div class="info-content">
            <input ng-model="vm.registryInfo.description" class="ui-input-white line-single"/>
          </div>
        </li>
        <li ng-if="vm.registryInfo.status===1"><span class="info-name">证书信息</span>
          <div class="info-content">
            <textarea ng-model="vm.registryInfo.certification" placeholder="请将证书文本粘贴至文本框" class="ui-input-white line-single certification-txt"></textarea>
          </div>
        </li>
      </ul>
      <div class="com-bottom-option">
        <button ng-click="vm.needValidRegistry=true;registryForm.$valid&amp;&amp;vm.saveRegistry()" class="ui-btn ui-btn-bright ui-btn-md">保存配置</button>
      </div>
    </tab>
    <tab heading="服务器" ng-click="vm.getServerInfo()" active="vm.tabActive[4].active" ui-sref="globalSetting.serverinfo">
      <ul ng-form="ng-form" name="serverForm" ng-class="{'need-valid':vm.needValidServer}" class="com-list-info">
        <li><span class="info-name not-align-input">服务器地址</span>
          <div class="info-content"><span class="txt-prompt">DomeOS API服务器访问地址</span>
            <input placeholder="https协议url请用“https://”开头" ng-model="vm.serverInfo.url" name="serverUrl" required="required" ng-pattern="/^[^\s]*$/" class="ui-input-white line-single"/>
          </div>
        </li>
      </ul>
      <div class="com-bottom-option">
        <button ng-click="vm.needValidServer=true;serverForm.$valid&amp;&amp;vm.saveServer()" class="ui-btn ui-btn-bright ui-btn-md">保存配置</button>
      </div>
    </tab>
    <tab heading="监控报警" ng-click="vm.getMonitorInfo()" active="vm.tabActive[5].active" ui-sref="globalSetting.monitorinfo">
      <ul ng-form="ng-form" name="monitorForm" ng-class="{'need-valid':vm.needValidMonitor}" class="com-list-info">
        <li><span class="info-name not-align-input">transfer</span>
          <div class="info-content"><span class="txt-prompt">监控数据转发组件</span>
            <div ng-repeat="tansfer in vm.monitorConfig.transfer" class="line-single">
              <input placeholder="请输入ip：port" name="serverUrl" ng-model="tansfer.text" ng-focus="$last&amp;&amp;vm.monitorIns.addItem('transfer')" class="ui-input-white full"/>
              <div ng-if="vm.monitorConfig.transfer.length&gt;1" class="txt-wrap"><a ng-click="vm.monitorIns.deleteArrItem('transfer',$index)" class="icon-delete"></a></div>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">graph</span>
          <div class="info-content"><span class="txt-prompt">监控数据存储组件</span>
            <div ng-repeat="graph in vm.monitorConfig.graph" class="line-single">
              <input placeholder="请输入ip：port" name="serverUrl" ng-model="graph.text" ng-focus="$last&amp;&amp;vm.monitorIns.addItem('graph')" class="ui-input-white full"/>
              <div ng-if="vm.monitorConfig.graph.length&gt;1" class="txt-wrap"><a ng-click="vm.monitorIns.deleteArrItem('graph',$index)" class="icon-delete"></a></div>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">query</span>
          <div class="info-content"><span class="txt-prompt">监控数据查询组件</span>
            <div class="line-single">
              <input placeholder="请输入ip：port" name="query" ng-model="vm.monitorConfig.query" class="ui-input-white full"/>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">hbs</span>
          <div class="info-content"><span class="txt-prompt">监控心跳服务器组件</span>
            <div class="line-single">
              <input placeholder="请输入ip：port" name="hbs" ng-model="vm.monitorConfig.hbs" class="ui-input-white full"/>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">judge</span>
          <div class="info-content"><span class="txt-prompt">报警判断组件</span>
            <div ng-repeat="judge in vm.monitorConfig.judge" class="line-single">
              <input placeholder="请输入ip：port" name="judge" ng-model="judge.text" ng-focus="$last&amp;&amp;vm.monitorIns.addItem('judge')" class="ui-input-white full"/>
              <div ng-if="vm.monitorConfig.judge.length&gt;1" class="txt-wrap"><a ng-click="vm.monitorIns.deleteArrItem('judge',$index)" class="icon-delete"></a></div>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">alarm</span>
          <div class="info-content"><span class="txt-prompt">报警事件处理组件</span>
            <div class="line-single">
              <input placeholder="请输入ip：port" name="alarm" ng-model="vm.monitorConfig.alarm" class="ui-input-white full"/>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">sender</span>
          <div class="info-content"><span class="txt-prompt">报警发送组件</span>
            <div class="line-single">
              <input placeholder="请输入ip：port" name="sender" ng-model="vm.monitorConfig.sender" class="ui-input-white full"/>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">nodata</span>
          <div class="info-content"><span class="txt-prompt">报警假数据填充组件</span>
            <div class="line-single">
              <input placeholder="请输入ip：port" name="nodata" ng-model="vm.monitorConfig.nodata" class="ui-input-white full"/>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">redis</span>
          <div class="info-content"><span class="txt-prompt">报警redis组件</span>
            <div class="line-single">
              <input placeholder="请输入ip：port" name="redis" ng-model="vm.monitorConfig.redis" class="ui-input-white full"/>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">apiSms</span>
          <div class="info-content"><span class="txt-prompt">报警短信发送接口。请和使用的短信发送平台保持一致</span>
            <div class="line-single">
              <input placeholder="请输入url" name="apiSms" ng-model="vm.monitorConfig.apiSms" class="ui-input-white full"/>
            </div>
          </div>
        </li>
        <li><span class="info-name not-align-input">apiMail</span>
          <div class="info-content"><span class="txt-prompt">报警邮件发送接口。请和使用的邮件发送平台保持一致</span>
            <div class="line-single">
              <input placeholder="请输入url" name="apiMail" ng-model="vm.monitorConfig.apiMail" class="ui-input-white full"/>
            </div>
          </div>
        </li>
      </ul>
      <div class="com-bottom-option">
        <button ng-click="vm.needValidMonitor=true;monitorForm.$valid&amp;&amp;vm.saveMonitor()" class="ui-btn ui-btn-bright ui-btn-md">保存配置</button>
      </div>
    </tab>
    <tab heading="Web SSH" ng-click="vm.getWebSsh()" active="vm.tabActive[6].active" ui-sref="globalSetting.sshinfo">
      <ul ng-form="ng-form" name="sshForm" ng-class="{'need-valid':vm.needValidSsh}" class="com-list-info">
        <li><span class="info-name not-align-input webssh-txt">Web SSH服务地址</span>
          <div class="info-content"><span class="txt-prompt">Web SSH登录服务访问地址（对应容器的访问地址）</span>
            <input placeholder="请输入ip：port" name="sshUrl" ng-model="vm.sshInfo.url" required="required" class="ui-input-white line-single"/>
          </div>
        </li>
      </ul>
      <div class="com-bottom-option">
        <button ng-click="vm.needValidSsh=true;sshForm.$valid&amp;&amp;vm.saveSsh()" class="ui-btn ui-btn-bright ui-btn-md">保存配置</button>
      </div>
    </tab>
    <tab heading="构建集群" ng-click="vm.initClusterInfo()" active="vm.tabActive[7].active" ui-sref="globalSetting.clusterinfo">
      <loading ng-if="vm.clusterLoadingIns.isLoading"></loading>
      <button ng-click="vm.needValidCluster=true;clusterForm.$valid&amp;&amp;vm.saveCluster()" ng-disabled="vm.clusterLoadingIns.isLoading" class="ui-btn ui-btn-bright ui-btn-md btn-cluster-save">保存配置</button><span class="cluster-detail">DomeOS的构建任务都在构建集群上运行。构建任务包括项目构建和镜像定制功能。除了运行构建任务，构建集群也可以用于部署其他服务。</span>
      <ul ng-form="ng-form" name="clusterForm" ng-class="{'need-valid':vm.needValidCluster}" class="com-list-info">
        <li><span class="info-name not-align-input">选择集群</span>
          <div class="info-content"><span class="txt-prompt">列表展示了“集群管理”中的所有集群，选择一个作为构建集群。</span>
            <div select-con="select-con" class="com-select-con line-single">
              <button class="ui-btn-select ui-btn ui-btn-white"><i class="icon-down"></i>{{vm.clusterInfo.clusterName||'选择集群'}}</button>
              <ul class="select-list">
                <li ng-repeat="cluster in vm.clusterList" class="select-item"><a ng-bind="cluster.name" ng-click="vm.toggleCluster(cluster)"></a></li>
              </ul>
            </div>
            <input type="hidden" ng-model="vm.clusterInfo.clusterName" required="required" name="clusterName"/><span ng-if="vm.needValidCluster&amp;&amp;clusterForm.clusterName.$invalid" class="txt-error">请选择集群</span>
          </div>
        </li>
        <li><span class="info-name">选择namespace</span>
          <div class="info-content"><span class="txt-prompt">在集群的namespace中选择一个，用于启动构建任务。</span>
            <div select-con="select-con" class="com-select-con line-single">
              <button class="ui-btn-select ui-btn ui-btn-white"><i class="icon-down"></i>{{vm.clusterInfo.namespace||'选择namespace'}}</button>
              <ul class="select-list">
                <li ng-repeat="namespace in vm.namespaceList" class="select-item"><a ng-bind="namespace.name" ng-click="vm.clusterInfo.namespace = namespace.name"></a></li>
              </ul>
            </div>
            <input type="hidden" ng-model="vm.clusterInfo.namespace" required="required" name="namespace"/><span ng-if="vm.needValidCluster&amp;&amp;clusterForm.namespace.$invalid" class="txt-error">请选择namespace</span>
          </div>
        </li>
      </ul>
      <div class="node-option"><span class="host-right">共有{{nodelistFiltered.length}}台主机
          <input placeholder="输入主机名查询" ng-model="vm.key.nodeKey" class="ui-input ui-input-search ui-input-fill"/></span><span class="host-detail">构建集群的主机列表，构建任务会在开启“用于构建”的主机上运行，请确保构建集群内有至少一台主机能够用于构建。</span></div>
      <table class="ui-table ui-table-dome table-hostlist">
        <thead>
          <tr>
            <th>主机名称</th>
            <th>IP</th>
            <th>CPU总量（个）</th>
            <th>内存总量（MB）</th>
            <th>运行实例（个）</th>
            <th>状态</th>
            <th>是否用于构建</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-if="!vm.nodeList||nodelistFiltered.length===0">
            <td colspan="7">无相关信息</td>
          </tr>
          <tr ng-repeat="node in nodelistFiltered=(vm.nodeList|filter:{name:vm.key.nodeKey})">
            <td ng-bind="node.name"></td>
            <td ng-bind="node.ip"></td>
            <td ng-bind="node.capacity.cpu"></td>
            <td ng-bind="node.capacity.memory"></td>
            <td ng-bind="node.runningPods"></td>
            <td ng-switch="node.status"><span ng-switch-when="Ready" class="txt-safe">在线</span><span ng-switch-default="ng-switch-default" class="txt-prompt">离线</span></td>
            <td>
              <dome-toggle ng-class="{'on':node.isUsedByBuild}" ng-click="node.isUsedByBuild = !node.isUsedByBuild"></dome-toggle>
            </td>
          </tr>
        </tbody>
      </table>
    </tab>
  </tabset>
</div>
<script type="text/ng-template" id="newPasswdModal.html">
  <div class="d-modal-header">修改密码</div>
  <div class="modal-body text-center">
    <ul ng-form="ng-form" role="form" name="pwForm" class="modal-info">
      <li><span class="info-name">新密码</span>
        <div class="info-content text-left">
          <input placeholder="8-20位" type="password" name="newPassword" ng-model="vmPw.passwd" ng-model-options="{updateOn:'default blur',debounce:{default:500,blur:0}}" required="required" ng-minlength="8" ng-maxlength="20" class="ui-input-white full"/><span ng-if="pwForm.newPassword.$dirty&amp;&amp;(pwForm.newPassword.$error.minlength||pwForm.newPassword.$error.maxlength)" class="txt-error">长度必须为8-20位</span>
        </div>
      </li>
    </ul>
  </div>
  <div class="modal-footer">
    <button ng-click="vmPw.cancel()" class="ui-btn ui-btn-sm ui-btn-white">取消</button>
    <button ng-click="pwForm.$valid&amp;&amp;vmPw.subPw()" class="ui-btn ui-btn-sm ui-btn-safe">确定</button>
  </div>
</script>